<?php
	function addPhase($id, $idProdFab, $desc, $img, $duree)
	{
		$cnx = dbconn();
		$sql = 'INSERT into Phase(nOrdrePhase, PRODUIT_FABRIQUE_idProd, descPhase, imgPhase, dureePhase) values (?, ?, ?, ?, ?)';
		$pq = $cnx->prepare($sql);
		$pq->bindParam(1, $id);
		$pq->bindParam(2, $idProdFab);
		$pq->bindParam(3, $desc);
		$pq->bindParam(4, $img);
		$pq->bindParam(5, $duree);
		$response=new WsResponse();
		if($pq->execute()){
		//succes de l'insert	
		$response->setStatusCode("1");
		$response->setStatusMessage("OK");
	}else{
		//echec de l'insert
		$response->setStatusCode("-1");
		$response->setStatusMessage("ECHEC AJOUT");
	}
	echo($response->toXml());
	}
	
	function deletePhase($id, $idProdFab){
	$cnx=dbconn();
	$sql = 'DELETE from Phase where nOrdrePhase=? and PRODUIT_FABRIQUE_idProd=?';
	$pq=$cnx->prepare($sql);
	$pq->bindParam(1, $id);
	$pq->bindParam(2, $idProdFab);
	$response= new WsResponse();
	if($pq->execute()){
		//succes delete
		$response->setStatusCode("1");
		$response->setStatusMessage("OK");
	}else{
		//echec de l'insert
		$response->setStatusCode("-1");
		$response->setStatusMessage("ECHEC AJOUT");
	}
	echo($response->toXml());
}

function updatePhase($id, $idProdFab, $desc, $img, $duree)
{
	$cnx=dbconn();
	$sql= 'UPDATE Phase SET descPhase=?, imgPhase=?, dureePhase=? WHERE nOrdrePhase=? AND PRODUIT_FABRIQUE_idProd=?';

	$pd=$cnx->prepare($sql);
	$pd->bindParam(1, $desc);
	$pd->bindParam(2, $img);
	$pd->bindParam(3, $duree);
	$pd->bindParam(4, $id);
	$pd->bindParam(5, $idProdFab);
	$response= new WsResponse();
	if($pd->execute()){

	$pd=$cnx->prepare($sql);
	$pq->bindParam(1, $id);
	$pq->bindParam(2, $idProdFab);
	$pq->bindParam(3, $desc);
	$pq->bindParam(4, $img);
	$pq->bindParam(5, $duree);
	$reponse= new WsResponse();
	if($pq->execute()){

		//succes delete
		$response->setStatusCode("1");
		$response->setStatusMessage("OK");
	}
	else
	{
		//echec de l'insert
		$response->setStatusCode("-1");
		$response->setStatusMessage("ECHEC AJOUT");
	}
	echo($response->toXml());
}
	}
	function getPhasesParProduit($idProdFab)
	{
		$datastring="";	
		$cnx=dbconn();
		$sql = 'SELECT nOrdrePhase, PRODUIT_FABRIQUE_idProd, descPhase, imgPhase, dureePhase FROM Phase pf  WHERE PRODUIT_FABRIQUE_idProd = ?';	
		$pq=$cnx->prepare($sql);	
		$pq->bindParam(1, $idProdFab);
		$pq->execute();
		while ($row = $pq->fetch(PDO::FETCH_OBJ))
		{
			$datastring=$datastring."<phase>";
			$datastring=$datastring."<nOrdrePhase>".$row->nOrdrePhase."</nOrdrePhase>";
			$datastring=$datastring."<PRODUIT_FABRIQUE_idProd>".$row->PRODUIT_FABRIQUE_idProd."</PRODUIT_FABRIQUE_idProd>";
			$datastring=$datastring."<descPhase>".$row->descPhase."</descPhase>";
			$datastring=$datastring."<imgPhase>".$row->imgPhase."</imgPhase>";
			$datastring=$datastring."<dureePhase>".$row->dureePhase."</dureePhase>";
			$datastring=$datastring."</phase>";
		}
		$response=new WsResponse();
		$response->setStatusCode("1");
		$response->setStatusMessage("OK");
		$response->setData($datastring);
		echo($response->toXml());
	}
	
?>